package com.youoor.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import com.youoor.common.base.BaseDao;
import com.youoor.common.base.BaseServiceImpl;
import com.youoor.dao.CardLinkDao;
import com.youoor.dao.UserCardDao;
import com.youoor.domain.CardLink;
import com.youoor.domain.UserCard;
import com.youoor.domain.UserCardQuery;
import com.youoor.service.UserCardService;

@Service(value="userCardService")
public class UserCardServiceImpl extends BaseServiceImpl<UserCard,UserCardQuery,Integer> implements UserCardService {
	private static final Logger logger = LoggerFactory.getLogger(UserCardServiceImpl.class);
	
	@Resource(name = "userCardDao")
	private UserCardDao userCardDao;
	
	@Resource(name = "cardLinkDao")
	private CardLinkDao cardLinkDao;
	
	public CardLinkDao getCardLinkDao() {
		return cardLinkDao;
	}

	public void setCardLinkDao(CardLinkDao cardLinkDao) {
		this.cardLinkDao = cardLinkDao;
	}

	public UserCardDao getUserCardDao() {
		return userCardDao;
	}

	public void setUserCardDao(UserCardDao userCardDao) {
		this.userCardDao = userCardDao;
	}

	@Override
	public BaseDao<UserCard, UserCardQuery, Integer> getBaseDao() {
		// TODO Auto-generated method stub
		return userCardDao;
	}

	@Override
	public void editCard(UserCard userCard,List<CardLink> links) {
		userCardDao.editCard(userCard);
		for (CardLink link:links) {
			 cardLinkDao.save(link);
		 }
	}

	@Override
	public Integer createCard(UserCard userCard, List<CardLink> links) {
		// TODO Auto-generated method stub
		 Integer cardId = userCardDao.newCard(userCard);
		 if(!CollectionUtils.isEmpty(links)) {
			 for (CardLink link:links) {
				 link.setCardId(cardId);
				 cardLinkDao.save(link);
			 }
		 }
		 
		 return 1;
	}

	@Override
	public UserCard getUserCardByUserId(Integer userId) {
		// TODO Auto-generated method stub
		return userCardDao.getUserCardByUserId(userId);
	}

	@Override
	public List<UserCard> getLatestList(Integer cardId,Integer num) {
		// TODO Auto-generated method stub
		return userCardDao.getCardListForLatest(cardId, num);
	}

	@Override
	public List<UserCard> getUserCardForView(Integer pageIndex, int limit) {
		// TODO Auto-generated method stub
		return userCardDao.getCardListForView(pageIndex, limit);
	}

	@Override
	public List<UserCard> getUserRecommendCardForView(int limit) {
		// TODO Auto-generated method stub
		return userCardDao.getUserRecommendCardForView(limit);
	}



	

}
